/**
 * @author scylla
 * @version V1.0
 * @Project echo-java-base
 * @Title pair
 * @Description *
 * @Package concurrent.mthread.synchronizeCodeBlock
 * @Since 2021/8/18 2:19 下午
 */
package concurrent.mthread.synchronizeCodeBlock;

import java.text.MessageFormat;

class Pair {
    private int x, y;

    public Pair(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public Pair() {
        this(0, 0);
    }


    public void incrementX() {
        x++;
    }

    public void incrementY() {
        y++;
    }

    @Override
    public String toString() {
        return MessageFormat.format("x: {0},y: {1}", x, y);
    }

    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }


    /**
     * @author chentl
     * @version V1.0
     * @project bigdata-cloud
     * @title Pair
     * @description Pair内部异常
     * @package concurrent.mthread.synchronizeCodeBlock
     * @date 2021/8/18 2:26 下午
     * @copyright: 武汉大数据产业发展有限公司 All rights reserved.
     */
    public class PairValueNotEqualException extends RuntimeException {
        public PairValueNotEqualException() {
            super("Pair values not equal: " + Pair.this);
        }
    }

    /**
     * 检查Pair中 x,y是否相等
     *
     * @author chentl
     * @since 2:27 下午 2021/8/18
     **/
    public void checkState() {
        if (x != y) throw new PairValueNotEqualException();
    }



}
